package com.swiftride.controller.app;

import cn.dev33.satoken.annotation.SaIgnore;
import com.swiftride.pojo.param.CustomerFineParam;
import com.swiftride.result.R;
import com.swiftride.service.ICustomerFineService;
import com.swiftride.service.ICustomerService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;


@Tag(name = "小程序乘客对象", description = "小程序乘客对象")
@RestController
@RequestMapping("/app/customer")
public class AppCustomerController {

    @Autowired
    private ICustomerService customerService;

    @Autowired
    public ICustomerFineService customerFineService;

    @Operation(summary = "获取openid", description = "openid获取接口")
    @Parameter(name = "openidCode", description = "获取openid的code", required = true)
    @GetMapping(value = "/register/{openidCode}")
    @SaIgnore
    public R register(@PathVariable("openidCode") @NotNull(message = "数据不能为空") String openidCode) {
        customerService.register(openidCode);
        return R.success();
    }

    @Operation(summary = "获取openid", description = "openid获取接口")
    @Parameter(name = "openidCode", description = "获取openid的code", required = true)
    @GetMapping(value = "/registerByPhone/{openidCode}/{phoneCode}")
    @SaIgnore
    public R registerByPhone(@PathVariable("openidCode") @NotNull(message = "数据不能为空") String openidCode,
                             @PathVariable("phoneCode") String phoneCode) {
        customerService.register(openidCode, phoneCode);
        return R.success();
    }

    @Operation(summary = "保存乘客罚款信息", description = "保存乘客罚款信息接口")
    @Parameter(name = "customerFineParam", description = "乘客罚款对象")
    @PostMapping("/customerFine")
    public R saveCustomerFine(@RequestBody @NotNull CustomerFineParam customerFineParam) {
        customerFineService.saveCustomerFine(customerFineParam);
        return R.success();
    }
}
